#include"stable_face_box.h"

void Solution::process(vector<FaceBox>& catch_queue, vector<Box>& det_face){
    int i, j, match_id;
    vector<int> erase_ids;
    float iou_score, max_iou_score;
    
    for(i=0;i<catch_queue.size();++i){
        max_iou_score = .0;
	    for(j=0;j<det_face.size();++j){
            iou_score = box_iou(det_face[j], catch_queue[i].boxes[0]); // use '0': just for simple
	        if(iou_score > max_iou_score){
                max_iou_score = iou_score;
                match_id = j;
            }
	    }
	    if(max_iou_score>iou_thresh_){
	        update_queue(det_face[match_id], catch_queue, i);
            det_face.erase(std::begin(det_face) + match_id);
	    }else{
	        erase_ids.push_back(i);
        }
    }

    int tmp_id;
    for(i=0;i<erase_ids.size();++i){
        tmp_id = erase_ids[i] - i;
        catch_queue.erase(std::begin(catch_queue) + tmp_id);
    }

    for(i=0;i<det_face.size();++i){
        vector<Box> boxes = {det_face[i]};
        FaceBox face_boxes;
        face_boxes.boxes = boxes;
        catch_queue.push_back(face_boxes);
    }
}

